<template>

    <div class="app-container">
        <uc-table url="/admin/handle/getInNonEmergencyPage" name="消防隐患" ref="nonWmergencyTable" pageable table-border :search-form="searchForm">
            <template slot="searchForm">
                <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
                    <!--搜索输入框-->
                    <el-form-item v-if="enterPriseHidden">
                        <el-select v-model="searchForm.enterpriseId" placeholder="请选择主体"  clearable @clear="clearInput">
                            <el-option v-for="(item,index) in enterpriseDominantList" :key="index"  :value="item.ucId" :label="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                    <!--搜索按钮--新增按钮-->
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
                    </el-form-item>
                </el-form>
            </template>
            <template slot="columns">
                <el-table-column prop="enterpriseName" label="所属主体" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="name" label="隐患名称" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="reportedUserName" label="上报人" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="reportedTime" label="上报时间" align="left" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        {{scope.row.reportedTime|dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column prop="content" label="隐患描述信息" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="address" label="操作" width="240" align="left" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <!--编辑按钮-->
                        <el-button  :disabled="scope.row.handleStatus==2" size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)" >已整改</el-button>
                        <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
                        <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </template>
        </uc-table>
    </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteInNonEmergency, updateInNonEmergency} from "@/api/nonEmergency";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";


export default {
    name: "NonEmergency",
    components: {UcTable},
    data(){
        return{
            searchForm:{
                deleted:false,
            },
            deleteLoading:false,
            enterpriseDominantList:[]
        }
    },
    created() {
        this.getInEnterpriseDominantList()
    },
  computed:{
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"||roleCode=="WB-ADMIN"
    }
  },
    methods:{
        handleSearch(){
            this.$refs.nonWmergencyTable.getTableData(1)
        },
        handleInfo(val){
            this.$router.push("/nonEmergency/nonEmergencyInfo/"+val.ucId)
        },
        handleEdit(val){
            updateInNonEmergency({ucId:val.ucId,handleStatus:2}).then(res=>{
                this.$notify.success({
                    title: '成功',
                    message: "成功"
                })
                this.handleSearch()
            }).catch(error=>{
                this.$notify.error({
                    title: '失败',
                    message: error.message
                })
            })
        },
        clearInput(){
            //清除企业下拉框
            this.searchForm.enterpriseId = null
            this.handleSearch()
        },
        handleDelete(val){
            this.$confirm('您确定要执行删除'+val.disPlayName+'这个隐患信息吗？', '提醒信息', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.deleteLoading = true
                deleteInNonEmergency(val).then(res=>{
                    this.deleteLoading = false
                    this.$notify.success({
                        title: '成功',
                        message: "删除隐患信息成功"
                    })
                    this.handleSearch()
                }).catch(res=>{
                    this.deleteLoading = false
                    this.$notify.error({
                        title: '失败',
                        message: res.msg
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        getInEnterpriseDominantList(){
            getInEnterpriseDominantList({deleted:false}).then(res=>{
                this.enterpriseDominantList = res.data
            }).catch(error=>{

            })
        }
    },

}
</script>

<style scoped>

</style>